package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.XMain;
import com.ruoyi.system.service.IXMainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售Controller
 * 
 * @author GGJ
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/system/main")
public class XMainController extends BaseController
{
    @Autowired
    private IXMainService xMainService;

    /**
     * 查询销售列表
     */
    @PreAuthorize("@ss.hasPermi('system:main:list')")
    @GetMapping("/xmain/list")
    public TableDataInfo list(XMain xMain)
    {
        startPage();
        List<XMain> list = xMainService.selectXMainList(xMain);
        return getDataTable(list);
    }

    /**
     * 导出销售列表
     */
    @PreAuthorize("@ss.hasPermi('system:main:export')")
    @Log(title = "销售", businessType = BusinessType.EXPORT)
    @PostMapping("/xmain/export")
    public void export(HttpServletResponse response, XMain xMain)
    {
        List<XMain> list = xMainService.selectXMainList(xMain);
        ExcelUtil<XMain> util = new ExcelUtil<XMain>(XMain.class);
        util.exportExcel(response, list, "销售数据");
    }

    /**
     * 获取销售详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:main:query')")
    @GetMapping(value = "/xmain/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(xMainService.selectXMainById(id));
    }

    /**
     * 新增销售
     */
    @PreAuthorize("@ss.hasPermi('system:main:add')")
    @Log(title = "销售", businessType = BusinessType.INSERT)
    @PostMapping("/xmain")
    public AjaxResult addXMain(@RequestBody XMain xMain)
    {
        return toAjax(xMainService.insertXMain(xMain));
    }

    /**
     * 修改销售
     */
    @PreAuthorize("@ss.hasPermi('system:main:edit')")
    @Log(title = "销售", businessType = BusinessType.UPDATE)
    @PutMapping("/xmain")
    public AjaxResult edit(@RequestBody XMain xMain)
    {
        return toAjax(xMainService.updateXMain(xMain));
    }

    /**
     * 删除销售
     */
    @PreAuthorize("@ss.hasPermi('system:main:remove')")
    @Log(title = "销售", businessType = BusinessType.DELETE)
	@DeleteMapping("/xmain/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xMainService.deleteXMainByIds(ids));
    }
}
